package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐相关功能")
public class SetMealController {
    //注入操作层
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    @ApiOperation("新增套餐")
    //接收json参数封装
    public Result setMealAdd(@RequestBody SetmealDTO setmealDTO) {
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
        PageResult listPage=setmealService.page(setmealPageQueryDTO);
        return Result.success(listPage);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询套餐")
    public Result<SetmealVO> setmealById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }

    /**
     * @param ids
     * @return
     */
    //TODO
    @DeleteMapping
    @ApiOperation("删除套餐")
    public Result delSetMeal(List<Long> ids){
        setmealService.delSetmealByIds(ids);

        return Result.success();
    }

    /**
     * 停售起售状态
     */
    @PostMapping("status/{status}")
    @ApiOperation("起售停售")
    public Result startAndStop(@PathVariable Integer status,Long id){
        setmealService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 套餐修改功能 根据套餐ID查询已完成
     */
    @PutMapping
    @ApiOperation("套餐修改")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }
}
